﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfoSoftGlobal;
using SistemaLib.Helpers;
using SistemaLib.Gestores;
using System.Web.Services;
using System.Web.Script.Services;
using System.Text;
using SistemaLib.sipe.util;

namespace SistemaWeb.Paginas
{
    public partial class CalendarioRecursos : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {   
            if (!IsPostBack)
            {
                CargarCombos();
                ElegirFechaActual();
            }
        }

        public void ElegirFechaActual()
        {
            cboAnio.SelectedValue = DateTime.Now.Year.ToString();
            cboMes.SelectedValue = DateTime.Now.Month.ToString();            
        }

        private void CargarCombos()
        {
            cboRecurso.DataSource = GestorRecursos.ListarRecursos();
            cboRecurso.DataTextField = "nombre";
            cboRecurso.DataValueField = "id";
            cboRecurso.DataBind();

            cboMes.DataSource = FuncionesMeses.CargarComboMeses(false);
            cboMes.DataTextField = "Description";
            cboMes.DataValueField = "Id";
            cboMes.DataBind();

            cboAnio.DataSource = Fechas.CargarComboAnios(10);
            cboAnio.DataTextField = "Description";
            cboAnio.DataValueField = "Id";
            cboAnio.DataBind();
        }

        [WebMethod, ScriptMethod]
        public static string GenerateXml(int idRH, int mes, int anio)
        { 
            StringBuilder xml = new StringBuilder();           
            xml.Append(HelperCharts.XmlGanttMensualRecurso(idRH, mes, anio));

            return xml.ToString();
        } 
    }
}
